<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff">
			<table id="basicInfo" class="displaytable" style="text-align: left;padding:20px;">
				<tr>
					<td width="15%">姓名</td>
					<td width="35%">
						<input type="text" style="width: 80%" class="easyui-textbox" data-options='required:true' id="input_NAME" name="NAME" />
					</td>
					<td width="15%">用户名</td>
					<td width="35%">
						<input type="text" style="width: 80%" class="easyui-textbox" id="input_USERNAME" name="USERNAME" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td>角色</td>
					<td>
						<input style="width: 80%" class="easyui-combobox" data-options='required:true' id="input_ROLE_NAME" name="ROLE_NAME" />
					</td>
					<td>所在部门</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-combobox" data-options='required:true' id="input_DEPARTMENT" name="DEPARTMENT" />
					</td>

				</tr>
				<tr>
					<td>身份证号码</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-textbox" id="input_NUMBER" name="NUMBER" data-options="required:true" />
					</td>
					<td>电话</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-textbox chechkPhone" id="input_PHONE" name="PHONE" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td>邮件地址</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-textbox" id="input_EMAIL" name="EMAIL" />
					</td>
				</tr>
				<tr class="hiddentr">
					<td>角色ID</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-textbox" id="input_ROLE_ID" name="ROLE_ID" />
					</td>
					<td>ID</td>
					<td>
						<input type="text" style="width: 80%" class="easyui-textbox" id="input_ID" name="ID" />
					</td>
				</tr>
			</table>
		</form>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src='../../../JS/SHA-1.js'></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var content;
		var currid = getID();
		var receipts_type = RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL + RECEIPT_DELETE_SYMBOL;
		var tooldata = [{
			"icon": "icon-clear",
			"func": "reset()",
			"functionname": "重置密码"
		}];
		console.log(hex_sha1("a198107"));
		content = AddReceiptsToolBar(receipts_type, tooldata);
		$("#toolbar").append(content);
		$(document).ready(function() {
			if(currid != AddFlag) {
				var _url = RemoteLinkAddress + '/user/findbyid.do?ID=' + currid;
				getRemoteData(_url);
			} else {
				currid = AddFlag;
			}
		});

		$("#input_ROLE_NAME").combobox({
			valueField: 'ID',
			textField: 'ROLE_NAME',
			mode: 'remote',
			method: 'get',
			panelHeight: 100,
			url: RemoteLinkAddress + '/role/listall.do',
			onSelect: function(result) {
				$("#input_ROLE_ID").textbox('setValue', result.ID);
			}
		});

		$("#input_DEPARTMENT").combobox({
			valueField: 'NAME',
			textField: 'NAME',
			mode: 'remote',
			method: 'get',
			panelHeight: 'auto',
			url: RemoteLinkAddress + '/department/listall.do',
		});

		function newdata() {
			currid = AddFlag;
			$("#ff").form('reset');
		}

		function save() {
			var tip;
			tip = checkPhoneNumber($("#input_PHONE").textbox('getValue'));
			if(tip != "验证成功") {
				$.messager.alert("警告", tip);
				return;
			}
			if($("#input_EMAIL").textbox('getValue').trim() != "") {
				tip = checkMail($("#input_EMAIL").textbox('getValue'));
				if(tip != "验证成功") {
					$.messager.alert("警告", tip);
					return;
				}
			}
			tip = IdentityCodeValid($("#input_NUMBER").textbox('getValue'));
			if(tip != "验证成功") {
				$.messager.alert("警告", tip);
				return;
			}
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			var _url;
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/user/save.do";
			} else {
				_url = RemoteLinkAddress + "/user/update.do";
			}
			saveData(_url);
		}

		function deletedata() {
			$.messager.confirm("确认", "是否删除", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/user/delete.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							var parentLocation;
							parentLocation = searchParent("UserList.html");
							parentLocation.dialogClose();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						currid = result.ID;
						getFormData(result);
					}
				}
			});
		}

		function saveData(_url) {
			var _data = submitFormData();
			delete _data.PASSWORD;//不能发送密码到后端
			$.ajax({
				type: "post",
				url: _url,
				dataType: "JSON",
				data: _data,
				success: function(result) {
					if(result.msg.search("success") > -1) {
						var parentLocation;
						parentLocation = searchParent("UserList.html");
						parentLocation.dialogClose();
					} else {
						if(result.msg.search("hasUser") > -1) {
							$.messager.alert("提示信息", "已存在该用户");
						} else {
							$.messager.alert("提示信息", result.msg);
						}

					}
				},
				error: function(result) {
					$.messager.alert('提示信息', '保存失败');
				}
			});
		}

		function reset() {
			var _data = submitFormData();
			//			_data.PASSWORD = "123456";
			$.messager.prompt({
				title: '重置密码',
				msg: '请输入你需要重置的密码',
				fn: function(r) {
					if(r) {
						_data.PASSWORD = hex_sha1(r);
						var _url = RemoteLinkAddress + "/user/resetpsw.do";
						$.ajax({
							type: "post",
							url: _url,
							dataType: "JSON",
							data: _data,
							success: function(result) {
								if(result.msg.search("success") > -1) {
									$.messager.alert("提示信息", "重置成功");
								} else {
									$.messager.alert("提示信息", result.msg);
								}
							},
							error: function(result) {
								$.messager.alert('提示信息', '重置失败');
							}
						});
					}
				}
			});

		}
	</script>

</html>